package com.ruoyi.project.system.controller;

import java.util.Date;
import java.util.List;

import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.project.system.domain.CourseCatalog;
import com.ruoyi.project.system.service.ICourseCatalogService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 课程章节Controller
 * 
 * @author ruoyi
 * @date 2020-10-07
 */
@RestController
@RequestMapping("/system/courseCatalog")
public class CourseCatalogController extends BaseController
{
    @Autowired
    private ICourseCatalogService courseCatalogService;

    /**
     * 查询课程章节列表
     */
    //@PreAuthorize("@ss.hasPermi('system:catalog:list')")
    @GetMapping("/list")
    public TableDataInfo list(CourseCatalog courseCatalog)
    {
        startPage();
        List<CourseCatalog> list = courseCatalogService.selectCourseCatalogList(courseCatalog);
        return getDataTable(list);
    }

    /**
     * 导出课程章节列表
     */
    @PreAuthorize("@ss.hasPermi('system:catalog:export')")
    @Log(title = "课程章节", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(CourseCatalog courseCatalog)
    {
        List<CourseCatalog> list = courseCatalogService.selectCourseCatalogList(courseCatalog);
        ExcelUtil<CourseCatalog> util = new ExcelUtil<CourseCatalog>(CourseCatalog.class);
        return util.exportExcel(list, "catalog");
    }

    /**
     * 获取课程章节详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:catalog:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id)
    {
        return AjaxResult.success(courseCatalogService.selectCourseCatalogById(id));
    }

    /**
     * 新增课程章节
     */
    @PreAuthorize("@ss.hasPermi('system:catalog:add')")
    @Log(title = "课程章节", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CourseCatalog courseCatalog)
    {
        courseCatalog.setCreateDt(new Date());
        return toAjax(courseCatalogService.insertCourseCatalog(courseCatalog));
    }

    /**
     * 修改课程章节
     */
    @PreAuthorize("@ss.hasPermi('system:catalog:edit')")
    @Log(title = "课程章节", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CourseCatalog courseCatalog)
    {
        return toAjax(courseCatalogService.updateCourseCatalog(courseCatalog));
    }

    /**
     * 删除课程章节
     */
    @PreAuthorize("@ss.hasPermi('system:catalog:remove')")
    @Log(title = "课程章节", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids)
    {
        return toAjax(courseCatalogService.deleteCourseCatalogByIds(ids));
    }
}
